import config from 'config'
import httpFetch from 'share/httpFetch'
import errorMessage from 'share/errorMessage'

export default {

  //订单列表
  getOrderList(params) {
    return new Promise((resolve, reject) => {
      httpFetch.get(`${config.baseUrl}/api/order/info/list`, params).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },

  //订单详情
  getOrderDetail(id) {
    return new Promise((resolve, reject) => {
      httpFetch.get(`${config.baseUrl}/api/order/info/detail`, id).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },

  //开票信息
  getInvoiceInfo(id) {
    return new Promise((resolve, reject) => {
      httpFetch.get(`${config.baseUrl}/api/operation/invoice/info`, id).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },

  //获取默认地址
  getDefaultAddress() {
    return new Promise((resolve, reject) => {
      httpFetch.get(`${config.baseUrl}/api/billing/contacts/default`).then(res => {
        resolve(res);
      }).catch(err => {
        errorMessage(err.response);
        reject(err.response);
      })
    })
  },

  //申请开票
  newInvoice(params) {
    return new Promise((resolve, reject) => {
      httpFetch.post(`${config.baseUrl}/api/operation/invoice/info`, params).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },

  //获取操作历史
  getHistoryList(params) {
    return httpFetch.get(`${config.baseUrl}/api/data/operate/log/list`, params)
  },
  
  //更新订单状态 - 取消订单
  updateOrderStatus(params) {
    return new Promise((resolve, reject) => {
      httpFetch.put(`${config.baseUrl}/api/order/info`, params).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },
  //服务大类类型
  getServiceType(params) {
    return httpFetch.get(`${config.baseUrl}/operationservice/public/enum/item/codes`, params)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      })

  },
}
